<template>
  <div class="starconfig">
    <div class="starleft">
      <div class="starcenter">
        <div class="title">星管家</div>
        <div class="baseconfig">基础配置</div>
      </div>
    </div>
    <div class="starcenterconfig">
      <div style="display:flex;align-items:center;" class="listone">
        <span style="width:70px;">首句文案：</span>
        <el-input
          style="flex:1;color: #fc9e76;"
          type="text"
          placeholder="请输入内容"
          v-model="firstCopywriting"
          maxlength="60"
          show-word-limit
        >
        </el-input>
      </div>
      <div style="display:flex;align-items:center;" class="listone">
        <span style="width:70px;">末句文案：</span>
        <el-input
          style="flex:1"
          type="text"
          placeholder="请输入内容"
          v-model="lastOpywriting"
          maxlength="60"
          show-word-limit
        >
        </el-input>
      </div>
      <div style="display:flex;align-items:center;" class="listone">
        <span style="width:70px;">解释文案：</span>
        <el-input
          style="flex:1"
          type="text"
          placeholder="请输入内容"
          v-model="explainCopywriting"
        >
        </el-input>
      </div>
      <div>
        <div style="display:flex;align-items:center;margin-bottom:5px;">
          <span class="left">首次进入弹框配置：主标题</span>
          <el-input
            type="text"
            placeholder="请输入内容"
            v-model="firstIntoName"
            maxlength="20"
            show-word-limit
            style="flex:1;margin-left:5px;"
          />
        </div>
        <div
          style="margin-left:103px;display:flex;align-items:center;margin-bottom:5px;"
        >
          <span>&nbsp;副标题</span>
          <el-input
            type="text"
            placeholder="请输入内容"
            v-model="firstIntoSubName"
            maxlength="20"
            show-word-limit
            style="flex:1;margin-left:5px;"
          />
        </div>
      </div>
      <div style="display:flex;align-items:center;margin-left:103px;">
        <span style="margin-right:12px;">&nbsp;&nbsp;配图</span>
        <el-upload
          class="avatar-uploader"
          action="https://api.xstarlife.com/systemapp/upload/singleFileUpload"
          :show-file-list="false"
          :headers="{ uploadScene: 'avatar' }"
          :on-success="img1success"
          :before-upload="beforeAvatarUpload"
        >
          <img
            v-if="firstIntoPic"
            :src="firstIntoPic"
            class="avatar"
            @mouseover="tip"
          />
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
      </div>
      <div>
        <div style="display:flex;align-items:center;margin-bottom:5px;">
          <span class="left">定制缓冲页面配置：主标题</span>
          <el-input
            type="text"
            placeholder="请输入内容"
            v-model="bufferIntoName"
            maxlength="20"
            show-word-limit
            style="flex:1;margin-left:5px;"
          />
        </div>
        <div
          style="display:flex;align-items:center;margin-left:103px;margin-bottom:5px;"
        >
          <span>&nbsp;副标题</span>
          <el-input
            type="text"
            placeholder="请输入内容"
            v-model="bufferIntoSubName"
            maxlength="20"
            show-word-limit
            style="flex:1;margin-left:5px;"
          />
        </div>
      </div>
      <div style="display:flex;align-items:center;margin-left:103px;">
        <span style="margin-right:12px;">&nbsp;&nbsp;配图</span>
        <el-upload
          class="avatar-uploader"
          action="https://api.xstarlife.com/systemapp/upload/singleFileUpload"
          :show-file-list="false"
          :headers="{ uploadScene: 'avatar' }"
          :on-success="img2success"
          :before-upload="beforeAvatarUpload"
        >
          <img
            v-if="bufferPic"
            :src="bufferPic"
            class="avatar"
            @mouseover="tip"
          />
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
      </div>
      <div style="display:flex;align-items:center;">
        <span style="margin-right:12px;">星管家头像配置:</span>
        <el-upload
          class="avatar-uploader"
          action="https://api.xstarlife.com/systemapp/upload/singleFileUpload"
          :show-file-list="false"
          :headers="{ uploadScene: 'avatar' }"
          :on-success="img3success"
          :before-upload="beforeAvatarUpload"
        >
          <img
            v-if="userAvatar"
            :src="userAvatar"
            class="avatar"
            @mouseover="tip"
          />
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
      </div>
    </div>
    <div class="starright">
      <div class="save" @click="save">保存</div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    systemConfigStarManagement: {
      type: Object,
      required: false
    }
  },
  data() {
    return {
      configType: "system_config_star_housekeeper",
      id: "",
      firstCopywriting: "",
      lastOpywriting: "",
      explainCopywriting: "",
      firstIntoName: "",
      firstIntoSubName: "",
      firstIntoPic: "",
      bufferIntoName: "",
      bufferIntoSubName: "",
      bufferPic: "",
      messageTip: true,
      userAvatar: "" // 星管家头像配置
    };
  },
  methods: {
    beforeAvatarUpload() {
      console.log("上传图片前校验");
    },
    img1success({ data }) {
      this.firstIntoPic = data;
    },
    img2success({ data }) {
      this.bufferPic = data;
    },
    img3success({ data }) {
      this.userAvatar = data;
    },
    tip() {
      if (this.messageTip) {
        this.messageTip = false;
        setTimeout(() => {
          this.$message.success("点击更换图片");
          this.messageTip = true;
        }, 3000);
      }
    },
    async save() {
      const data = {
        systemConfigStarManagement: {
          configType: this.configType,
          firstCopywriting: this.firstCopywriting,
          lastOpywriting: this.lastOpywriting,
          explainCopywriting: this.explainCopywriting,
          firstIntoName: this.firstIntoName,
          firstIntoSubName: this.firstIntoSubName,
          firstIntoPic: this.firstIntoPic,
          bufferIntoName: this.bufferIntoName,
          bufferIntoSubName: this.bufferIntoSubName,
          bufferPic: this.bufferPic,
          userAvatar: this.userAvatar
        }
      };
      if (this.id) {
        data.systemConfigStarManagement.id = this.id;
      }
      await this.$http({
        url: "/hsssystemadmin/config/system/updateSystemConfig",
        method: "POST",
        data
      }).then(() => {
        this.$message.success("星管家配置保存成功");
        this.$emit("research");
      });
    }
  },
  watch: {
    systemConfigStarManagement(newvalue) {
      if (newvalue) {
        const {
          configType,
          id,
          firstCopywriting,
          lastOpywriting,
          explainCopywriting,
          firstIntoName,
          firstIntoSubName,
          firstIntoPic,
          bufferIntoName,
          bufferIntoSubName,
          bufferPic,
          userAvatar
        } = newvalue;
        this.configType = configType;
        this.id = id;
        this.firstCopywriting = firstCopywriting;
        this.lastOpywriting = lastOpywriting;
        this.explainCopywriting = explainCopywriting;
        this.firstIntoName = firstIntoName;
        this.firstIntoSubName = firstIntoSubName;
        this.firstIntoPic = firstIntoPic;
        this.bufferIntoName = bufferIntoName;
        this.bufferIntoSubName = bufferIntoSubName;
        this.bufferPic = bufferPic;
        this.userAvatar = userAvatar;
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.starconfig {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
  .starleft {
    width: 150px;
    min-height: 150px;
    background-color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    .starcenter {
      width: 100px;
      height: 70px;
      .title {
        width: 100%;
        height: 35px;
        background-color: #f56a23;
        font-size: 22px;
        color: #fff;
        line-height: 35px;
        text-align: center;
      }
      .baseconfig {
        width: 100%;
        height: 35px;
        font-size: 22px;
        line-height: 35px;
        text-align: center;
        color: #aaa;
      }
    }
  }
  .starright {
    width: 150px;
    min-height: 150px;
    background-color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    .save {
      width: 70px;
      height: 40px;
      font-size: 22px;
      text-align: center;
      color: #fff;
      background-color: #00cb75;
      line-height: 40px;
    }
  }
  .starcenterconfig {
    font-size: 12px;
    flex: 1;
    margin: 0 10px;
    padding: 20px 10px;
    box-sizing: border-box;
    background-color: #fff;
    .listone {
      margin-bottom: 5px;
      display: flex;
      align-items: center;
    }
    /deep/ .el-input {
      font-size: 12px;
      height: 30px;
      box-sizing: border-box;
      .el-input__inner {
        height: 30px;
        box-sizing: border-box;
      }
    }
    /deep/ .avatar-uploader .el-upload {
      border: 1px dashed #d9d9d9;
      border-radius: 6px;
      cursor: pointer;
      position: relative;
      overflow: hidden;
    }
    /deep/ .avatar-uploader .el-upload:hover {
      border-color: #409eff;
    }
    /deep/ .avatar-uploader-icon {
      font-size: 14px;
      color: #8c939d;
      width: 50px;
      height: 50px;
      line-height: 50px;
      text-align: center;
    }
    /deep/ .avatar {
      width: 50px;
      height: 50px;
      display: block;
    }
  }
}
</style>
